package com.briup.mt.web.controller;

import com.briup.mt.bean.Module;
import com.briup.mt.service.IModuleService;
import com.briup.mt.utils.Message;
import com.briup.mt.utils.MessageUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/Module")
@Validated
public class ModuleController {
    @Autowired
    private IModuleService moduleService;

    @GetMapping("Query")
    public Message query(String name, String status){
        List<Module> list = moduleService.query(name, status);
        return MessageUtil.success(list);
    }

    @PostMapping("SaveOrUpdate")
    public Message saveOrUpdate(Module module){
        moduleService.saveOrUpdate(module);
        return MessageUtil.success("操作成功");
    }

    @DeleteMapping("DeleteById")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "模块id", required = true, paramType = "query")
    })
    public Message deleteById(@NotNull Long id){
        moduleService.deleteById(id);
        return MessageUtil.success("删除成功");
    }
}
